/** @jsxImportSource @emotion/react */
import * as React from "react";
import {CCell, Cell, Table, TableBody, TableHead, TableRow, Text, } from "customize-easy-ui-component";
import {DirectLink, Link as RouterLink,} from "../../routing/Link";
import {useMeasureTable} from "../hook/useMeasure";
import {useJudgmentTable} from "../hook/useJudgment";
import {Each_ZdSetting, useRep2hTableViewer, useRep2hTableViewerX} from "../hook/useRepTableEditor";
import {config适装} from "../movable/tanker/orcBase";
import {RepLink, SelectHookfork} from "../common/base";
import {calcAverageArrObj} from "../../common/tool";
import {config元件, items元件} from "../boiler/power/editPresCm";


/**有判定栏的测量结果记录表
 * @property mem: 备注的存储名
* */
export const 测量判定Amus = ({orc, rep, label, config, fixed: userFixed, tag = 'Measure', children, mem, nseq
                 }: {
                   orc: any, rep: any, label: string, config: any[], fixed?: string[], tag?: string, children?: any,mem?: string, nseq?:boolean
                 }
) => {
  const fixed=userFixed? userFixed :
          nseq? ["5%", "3%", "7%", "%", "3.8%", "7%", "8%", "7.1%", "5.2%"] :
              ["2.6%", "5%", "3%", "7%", "%", "3.8%", "7%", "8%", "7.1%", "5.2%"];
  //【概念乱】判定栏目和允许值栏目两个实际是不同的。@ 前者是不可以输入的。后者是用户可与修改的录入项。
  //栏目的布局顺序=...单位，判定标准，x项目名字，其它的。
  const renderMeasure = useJudgmentTable({rep, orc, config, nseq});
  //普通版  const renderMeasure = useMeasureTable({rep, orc, config, allowableV:true});
  const 观测备注: string[] = mem ? orc?.[mem] : '';
  return <>
    <Text variant="h4" css={{
      marginTop: '1rem',
    }}>{label}</Text>
    <Table id={tag} fixed={ fixed } css={{borderCollapse: 'collapse'}} tight miniw={800}>
      <TableHead>
        <TableRow>
         {!nseq &&  <CCell><Text css={{fontSize: '0.7rem'}}>序号</Text></CCell>}
          <CCell colSpan={2}><Text css={{fontSize: '0.75rem'}}>项目编号</Text></CCell><CCell colSpan={2}>观测内容与要求</CCell><CCell>单位</CCell>
          <CCell><Text css={{fontSize: '0.75rem'}}>判断标准</Text></CCell><CCell>观测值</CCell><CCell>结果值</CCell><CCell><Text css={{fontSize: '0.75rem'}}>结果判定</Text></CCell>
        </TableRow>
      </TableHead>
      <TableBody>
        <DirectLink href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/${tag}?original=1#${tag}`}>
          {renderMeasure}
          {mem  &&  <TableRow>
                <CCell>备注</CCell>
                <Cell colSpan={nseq? 8:9}>
                  <div css={{minHeight: '1rem', whiteSpace: 'pre-wrap'}}>
                    {观测备注 || '／'}
                  </div>
                </Cell>
              </TableRow>
          }
        </DirectLink>
      </TableBody>
    </Table>
    {children}
  </>;
};

const config仪器表=[['仪器名称','n',9],['仪器编号','i',9],] as Each_ZdSetting[];
/**报告的 仪器表 ：内嵌表格的部分
 * @property mem: 备注的存储名
 * TableHead 不支持很多行的，跨页不显示。 父辈的<CCell css={{padding: 0}}>
 * 表格的 链接 RepLink 只能在放 必须头尾分离的各自嵌套。
 * */
export const 仪器简表Amus = ({orc, rep, label='主仪器设检验', fixed =["4%", "28%", "18%", "4%", "%", "18%" ],
           tag = 'Instrument', children
         }: { orc: any, rep: any, label?: string, fixed?: string[], tag?: string, children?: any }
) => {
  const [renderRows,headRows]=useRep2hTableViewerX({
                table:'仪器表',config:config仪器表, orc, nhead:false, seqCl:<Text css={{fontSize:'0.75rem'}}>序号</Text>, });
         // const [renderRows,headRows]=useRep2hTableViewer(config仪器表, '仪器表', orc,false,true,true,'序号');
            //主体应该x行      instanceof Array;
    // const rowCnts=Array.isArray(renderRows)? renderRows.length : 1;
  return <Table fixed={ fixed } css={{borderCollapse: 'collapse', height:'fill-available'}} tight miniw={800}>
      <TableHead>
          <RepLink ori rep={rep} tag={tag}>
          {headRows}
          </RepLink>
      </TableHead>
      <TableBody>
          <RepLink ori rep={rep} tag={tag}>
          {renderRows}
          </RepLink>
        </TableBody>
    </Table>;
};
